package YAPclient;

import java.net.DatagramPacket;
import java.net.SocketException;

import YAPenvironment.YAPconstant;


/**
 * This thread is for receiving UDP-packages, i.e. in-game playground information containing the
 * current position of every game object
 */
public class UDPReceiverThread extends Thread{

	volatile boolean run=true;
	String sep=YAPconstant.C_SEPARATOR;
	
	public void run(){
		while(run){
			byte buf[] = new byte[450];
			DatagramPacket pack = new DatagramPacket(buf, buf.length);
			try{
				DataModul.dSocket.receive(pack);
				String strMsg= new String(pack.getData());
				
				/*
				 * TODO: test if everything is ok? maybe
				 */
				DataModul.parseThread.setPlayGround(strMsg);
			}catch (SocketException e){
				if(!run)
					break;
			}catch (Exception e){
				if(YAPconstant.C_DEBUG){ e.printStackTrace(); }
			}
		}
		
	}

	public void close(){
		run=false;
		try{
			this.interrupt();
		}catch(Exception e){
			//ignore; dont care... NANANA!
		}
	}
}
